package studentmanager;

import java.util.ArrayList;
import java.util.Scanner;

public class studentManager {
    static  ArrayList<Student> list = new ArrayList<>();
    public static void main(String[] args) {
        boolean like=true;
        while(like){
        System.out.println("------------------欢迎来到学生管理系统------------------");
        System.out.print("1 添加学生" + "\t");
        System.out.print("2 删除学生" + "\t");
        System.out.print("3 修改学生" + "\t");
        System.out.print("4 查看学生" + "\t");
        System.out.println("5 退出");
            System.out.println("管理系统--------------");
            System.out.println("请选择序号");
        Scanner sc = new Scanner(System.in);
        int action = sc.nextInt();
        switch (action) {
            case 1:
                System.out.println("添加学生");
                addStudent();
                break;
            case 2:
                System.out.println("删除学生");
                ShanChu();
                break;
            case 3:
                System.out.println("修改学生");
                xiugai();
                break;
            case 4:
                System.out.println("查看学生");
                student();
                break;
            case 5:
                System.out.println("退出系统");
                like=false;
                break;
            }
        }
    }
    private static void addStudent() {
        System.out.println("请输入学号：");
        Scanner so = new Scanner(System.in);
        String idNumber = so.nextLine();
        System.out.println("请输入姓名：");
        String name = so.nextLine();
        System.out.println("请输入手机号：");
        String phoneNumber = so.nextLine();
        System.out.println("请输入年龄");
        int age = so.nextInt();
        Student student = new Student(idNumber, name, age, phoneNumber);
        list.add(student);
        System.out.println("添加成功");

    }
    private static void student(){
        for(int i=0;i<list.size();i++){
            Student student=list.get(i);
            System.out.println(student.getIdNumber()+"\t"+student.getName()+"\t"+student.getPhoneNumber()+"\t"+student.getAge());
        }
    }
    private static void ShanChu() {
        System.out.println("请输入删除学生的学号");
        Scanner sc = new Scanner(System.in);
        String idNumber = sc.nextLine();
        boolean like = false;
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if (idNumber.equals(student.getIdNumber())) {
                list.remove(i);
                System.out.println("删除成功");
                System.out.println(student.getIdNumber() + "\t" + student.getName() + "\t" + student.getAge() + "\t" + student.getPhoneNumber());
                like = true;
                break;
            }
            if (!like) {
                System.out.println("未找到对应学号的学生");
            }
        }
    }
        private static void xiugai() {
            System.out.println("请输入要修改学生的学号");
            Scanner sc = new Scanner(System.in);
            String idNumber = sc.nextLine();
            for (int i = 0; i < list.size(); i++) {
                Student student = list.get(i);
                if (idNumber.equals(student.getIdNumber())) ;
                System.out.println("请输入学生的新的姓名");
                String newName = sc.nextLine();
                System.out.println("请输入学生新的手机号");
                String phoneNew = sc.nextLine();
                System.out.println("请输入学生新的年龄");
                int age = sc.nextInt();
                student.setIdNumber(newName);
                student.setName(newName);
                student.setPhoneNumber(phoneNew);
                student.setAge(age);
                list.set(i, student);
            }
        }
        private static void listStuent () {
            System.out.println("谢谢你的使用");
        }
    }